<% content_for :content do %>

  <!-- widget grid -->
  <section id="widget-grid" class="">
  
    <div class="row">
      <div class="col-sm-12">
        <div class="well">

          <%= simple_form_for :activity, url: admin_activities_path, :defaults => { :input_html => { :class => "form-control" } }, method: 'get', html: { class: "form-inline" } do |f| %>
            <label>Table</label>
            <%= f.input_field :item_type, selected: params[:activity][:item_type], collection: @tables, label: false, prompt: '全部' %>
            <%= f.input_field :field, value: params[:activity][:field], placeholder: "field" %> =
            <%= f.input_field :value, value: params[:activity][:value], placeholder: "value" %>
            <div class="form-group string">
            <%= f.text_field :start_date, class: "form-control datepicker", "data-dateformat" => "yy-mm-dd", value: params[:activity][:start_date], placeholder: "开始时间" %>
            </div>
            <div class="form-group string">
              <%= f.text_field :end_date, class: "form-control datepicker", "data-dateformat" => "yy-mm-dd", value: params[:activity][:end_date],placeholder: "结束时间" %>
            </div>
            <%= f.submit "搜索", :class => "btn btn-default"%>
          <% end %>

        </div> <!-- end well div -->

      </div>
    </div>

    <!-- row -->
    <div class="row">

      <div class="col-sm-12">
        <% if @tip %>
          <div class="alert alert-warning fade in">
            <button class="close" data-dismiss="alert">
              ×
            </button>
            <i class="fa-fw fa fa-warning"></i>
            <strong>提醒</strong> <%= @tip %>
          </div>
        <% end %>
      </div>

      <% if @error %>
      <div class="col-sm-12">
        <div class="alert alert-danger fade in">
          <button class="close" data-dismiss="alert">
            ×
          </button>
          <i class="fa-fw fa fa-times"></i>
          <strong>警告!</strong> <%= @error %>
        </div>
      </div>
      <% else %>
      <!-- NEW WIDGET START -->
      <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        
        <!-- Widget ID (each widget will need unique ID)-->
        <div class="jarviswidget jarviswidget-color-darken" id="wid-id-1" data-widget-editbutton="false" data-widget-colorbutton="false" data-widget-deletebutton="false">
          <!-- widget options:
          usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">

          data-widget-colorbutton="false"
          data-widget-editbutton="false"
          data-widget-togglebutton="false"
          data-widget-deletebutton="false"
          data-widget-fullscreenbutton="false"
          data-widget-custombutton="false"
          data-widget-collapsed="true"
          data-widget-sortable="false"

          -->
          <header>
            <span class="widget-icon"> <i class="fa fa-table"></i> </span>
            <h2>操作日志</h2>
          </header>

          <!-- widget div-->
          <div>

            <!-- widget edit box -->
            <div class="jarviswidget-editbox">
              <!-- This area used as dropdown edit box -->
            </div>
            <!-- end widget edit box -->

            <!-- widget content -->
            <div class="widget-body no-padding">

          		<% @versions.each do |v| %>
            		<div class="well well-sm well-light activity_row">
									<span class="label label-primary"><%= v.item_type %></span> { <%=v.item_id%> }  <%= v.event %>  by <%= Admin.where(id: v.whodunnit).first.try(:email) %>, <%= beautiful_time v.created_at %>
									<br>
									<div class="changeset">
										changes: <br/>
										<% v.changeset.each do |key,value| %>
											<p class="activity_detail"><%=key%>: <code><%= value[0] %></code> => <code><%= value[1] %></code></p>
										<% end %>
									</div>
								</div>
							<% end %>

            </div>
            <!-- end widget content -->

          </div>
          <!-- end widget div -->

        </div>
        <!-- end widget -->
  
      </article>
      <!-- WIDGET END -->
      <% end %>
    </div>
  
    <!-- end row -->

  </section>
  <!-- end widget grid -->

<% end %>

<% content_for :js do %>
	<%= javascript_include_tag "admin/activities" %>
<% end %>